home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / tnos / tnos100s / tnos.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-15  |  10.6 KB  |  471 lines

  1. /* New routines added by TNOS/KO4KS version of NOS */
  2.  
  3. #include "vmsmgr.hpp"
  4. #include <conio.h>
  5. #include <ctype.h>
  6. #include <dos.h>
  7. #include <time.h>
  8. #include "config.h"
  9.  
  10. vmsmgr *VMSscreens;
  11. #define ASCII_TYPE 0
  12. #define    READ_TEXT    "rt"
  13. int myVMSinited = 0;
  14. int STATLINE = 0;
  15. char *NextCmdMsg;
  16. short NextCmd;
  17. static unsigned char orgMode;
  18. unsigned char SCREENwidth = 80, SCREENlength = 25;
  19. char vgaDesired = 0;
  20. extern char statversion[];
  21. extern int BbsUsers, FtpUsers, Tutored;
  22. extern int main_exit;            /* from main program (flag) */
  23.  
  24. extern "C"     {
  25. void log(int s,char *fmt, ...);
  26. int tprintf (char *fmt, ...);
  27. int socklen (int s,int rtx);
  28. int setbool (int *var,char *label,int argc,char *argv[]);
  29. int CountConfUsers (void);
  30. void rip (char *);
  31.  
  32. // from dirutil.h
  33. struct cur_dirs {
  34.            int drv;
  35.            char * curdir[27];
  36.            char * dir;                
  37. } ;
  38.  
  39.  
  40. // from session.h
  41. struct screen {
  42.     char *save;        /* Screen save buffer */
  43.     int row;        /* Saved cursor location */
  44.     int col;
  45.     unsigned char attr;
  46.     unsigned char statline;
  47. };
  48.  
  49. struct ttystate {
  50.     struct mbuf *line;    /* Line buffer */
  51.     int echo;        /* Keyboard local echoing? */
  52.     int edit;        /* Local editing? */
  53.     int crnl;        /* Translate cr to lf? */
  54. };
  55.  
  56. /* Session control structure; only one entry is used at a time */
  57. struct session {
  58.     int type;
  59. #define    FREE    0
  60. #define    TELNET    1
  61. #define    FTP    2
  62. #define    AX25TNC    3
  63. #define    FINGER    4
  64. #define    PING    5
  65. #define NRSESSION 6
  66. #define    COMMAND    7
  67. #define    MORE    8
  68. #define    HOP    9
  69. #define    TIP    10
  70. #define    PPPPASS    11
  71. #define DIAL    12
  72. #define DQUERY    13
  73. #define DCLIST    14
  74. #define    RLOGIN    15
  75. #define TRACESESSION 16
  76.  
  77.     char *name;    /* Name of remote host */
  78.     union {
  79.         struct ftpcli *ftp;
  80.         struct telnet *telnet;
  81.     } cb;
  82.     struct proc *proc;    /* Primary session process (e.g., tn recv) */
  83.     struct proc *proc1;    /* Secondary session process (e.g., tn xmit) */
  84.     struct proc *proc2;    /* Tertiary session process (e.g., upload) */
  85.     int s;            /* Primary network socket (control for FTP) */
  86.     FILE *record;        /* Receive record file */
  87.     char *rfile;        /* Record file name */
  88.     FILE *upload;        /* Send file */
  89.     char *ufile;        /* Upload file name */
  90.     struct ttystate ttystate;
  91.     struct screen *screen;
  92.     int input;        /* Input socket */
  93.     int output;        /* Output socket */
  94.     int flowmode;        /* control "more" mode */
  95.     int row;        /* Rows remaining until "more" */
  96.     int morewait;        /* Output driver is waiting on us */
  97.     int tsavex;        /* Save for x top screen */
  98.     int tsavey;        /* Save for y top screen */
  99.     int bsavex;        /* Save for x bottom screen */
  100.     int bsavey;        /* Save for y bottom screen */
  101.     int split;        /* Signal for split screen */
  102.     struct cur_dirs *curdirs; 
  103.     int index;        /* session # (0 - (Nsessions - 1)) */
  104. };
  105. #define    NULLSESSION    (struct session *)0
  106. extern unsigned Nsessions;        /* Maximum number of sessions */
  107. extern struct session *Sessions;    /* Session descriptors themselves */
  108. extern struct session *Current;
  109. extern struct session *Command;
  110. extern struct session *Lastcurr;    /* Last non-command session */
  111. extern struct session *Trace;
  112. struct session *ScreenOwner;        /* Session currently displayed */
  113. }
  114.  
  115.  
  116. void realvmsstat ()
  117. {
  118. unsigned long lng;
  119.  
  120.     lng = VMSscreens->size();
  121.     lng *= VMSscreens->elements();
  122.     tprintf ("VMS mode - %s, %-lu bytes in use for screens ",
  123.         VMSscreens->inmemory() ? "Extended Memory" :
  124.         "Temporary Disk File", lng);
  125.     lng = VMSscreens->elements();
  126.     tprintf ("(%-lu/%-lu)\n", VMSscreens->size(), lng);
  127. }
  128.  
  129. void realVMSinit ()
  130. {
  131. struct text_info tr;
  132. size_t scrsize;
  133.  
  134.     gettextinfo(&tr);
  135.     orgMode = tr.currmode;
  136.     if (vgaDesired)        {
  137.         textmode (C4350);
  138.         gettextinfo(&tr);
  139.         }
  140.     SCREENwidth = tr.screenwidth;
  141.     SCREENlength = tr.screenheight;
  142.     window (1,1,SCREENwidth,SCREENlength);
  143.     scrsize = 2*tr.screenheight*tr.screenwidth;
  144.     if (myVMSinited == 0)    {
  145.         VMSscreens = new vmsmgr(scrsize, Nsessions);
  146.         myVMSinited = 1;
  147.         }
  148. }
  149.  
  150. void realVMSterm ()
  151. {
  152.     delete VMSscreens;
  153.     textmode (orgMode);
  154. }
  155.  
  156.  
  157. void realstowit (size_t index, int save, unsigned char attr)
  158. {
  159. char far *nerf;
  160. register int k, l, split;
  161. register char *cp;
  162.  
  163.     nerf = (char far*) farmalloc(VMSscreens->size());
  164.     if (save)    {
  165.         gettext(1,1,SCREENwidth,SCREENlength,nerf);
  166.         VMSscreens->stow (nerf, index);
  167.         }
  168.     else    {
  169.         VMSscreens->fetch (nerf, index);
  170.         if (attr & 0x80)    {
  171.             attr &= 0x7f;
  172.             l = (VMSscreens->size() / 2);
  173.             split = Sessions[index].split;
  174.             if (split)
  175.                 l -= 160;    // last 2 lines reversed
  176.             cp = (nerf + 1);
  177.             for (k = 0; k < l; k++)    {
  178.                 *cp &= 8;    // keep high video bit
  179.                 *cp |= attr;
  180.                 cp += 2;
  181.                 }
  182.             attr = ((attr & 0x0f) << 4) + ((attr & 0x70) >> 4);
  183.             if (split)
  184.                 for (k = 0; k < 160; k++)    {
  185.                     *cp &= 8;    // keep high video bit
  186.                     *cp |= attr;
  187.                     cp += 2;
  188.                 }
  189.             }
  190.         puttext (1,1,SCREENwidth,SCREENlength,nerf);
  191.         }
  192.     farfree (nerf);
  193. }
  194.  
  195.  
  196.  
  197. extern "C"    {
  198. long sendfile(FILE *fp,int s,int mode,int hash);
  199. int chksession (struct session *sp);
  200. int ssenabled (void);
  201.  
  202. int DisplayFile (char *fname,int socket)
  203. {
  204. FILE *fp;
  205. int size = 0;
  206. char buf[100];
  207.  
  208.     if(fp = fopen(fname,READ_TEXT)) {
  209.         sendfile(fp,socket,ASCII_TYPE,0);
  210.         size = ftell (fp);
  211.         fclose(fp);
  212.         }
  213.     return (size);
  214. }
  215.  
  216. void stowit (size_t index, int save, unsigned char attr)
  217. {
  218.     realstowit (index, save, attr);
  219. }
  220.  
  221. void VMSinit ()
  222. {
  223. int i;
  224.     realVMSinit ();
  225. //    _OvrInitExt (0, 0);
  226. }
  227.  
  228. void VMSterm ()
  229. {
  230.     realVMSterm ();
  231. }
  232.  
  233. void vmsstat ()
  234. {
  235.     realvmsstat ();
  236. }
  237.  
  238.  
  239. int SYSback = 40, SYSfore = 37;
  240. static char nope[] = "Color '%s' unknown!\nAvailable colors: black, red, green, cyan, blue, magenta, and white\n";
  241. //static char setem[] = "\x1b[%-2d;%-2dm";
  242. static int backs[8] = {0, 4, 2, 0, 1, 5, 3, 7};
  243. static int fores[8] = {0, 4, 2, 0, 1, 5, 3, 7};
  244.  
  245. void
  246. setscreens (int back, int fore, int clr)
  247. {
  248. char theback;
  249.  
  250.     if (!back && !fore)    {    // if both black, use system colors
  251.         back = SYSback;
  252.         fore = SYSfore;
  253.         back = backs[back - 40];
  254.         fore = fores[fore - 30];
  255.         }
  256.     textbackground (back);
  257.     textcolor (fore);
  258. //    tprintf (setem, back, fore);
  259.     theback = back;
  260.     asm    {
  261.         mov ah,0bh        // set background border
  262.         mov bh,00h
  263.         mov bl,theback
  264.         int 10h            // call driver
  265.         }
  266.     if (clr)
  267.         clrscr ();
  268. }
  269.  
  270.  
  271. int
  272. getcolor (char *str)
  273. {
  274. char *ptr;
  275.     for (ptr = str; *ptr; ptr++)
  276.         *ptr = tolower (*ptr);
  277.     switch (*str)    {
  278.         case 'r':    return 31;
  279.         case 'g':    return 32;
  280.         case 'm':    return 35;
  281.         case 'c':    return 36;
  282.         case 'w':    return 37;
  283.         case 'b':    if (str[1] != 'l')
  284.                     return 0;
  285.                 switch (str[2])    {
  286.                     case 'a':    return 30;
  287.                     case 'u':    return 34;
  288.                 }
  289.         default:    return 0;
  290.         }
  291. }
  292.  
  293. /* Set terminal colors */
  294. int
  295. docolor (int argc, char *argv[], void *p)
  296. {
  297. int temp;
  298. int back, fore;
  299. struct session *sp;
  300.  
  301.     temp = getcolor (argv[1]);
  302.     if (!temp)
  303.         tprintf (nope, argv[1]);
  304.     else    {
  305.         back = temp + 10;
  306.         temp = getcolor (argv[2]);
  307.         if (!temp)
  308.             tprintf (nope, argv[2]);
  309.         else    {
  310.             fore = temp;
  311.             if (argc > 3)    {
  312.                 temp = atoi(argv[3]);
  313.                 if (temp)    {
  314.                     sp = &Sessions[temp];
  315.                     if (chksession (sp))
  316.                         sp->screen->attr = (((backs[back - 40] << 4) + (fores[fore - 30])) | 0x80);
  317.                 }
  318.             } else    {
  319.                 SYSback = back;
  320.                 SYSfore = fore;
  321.                 setscreens (0, 0, 1);
  322.             }
  323.         }
  324.     }
  325.     return 0;
  326. }
  327.  
  328. void
  329. statlog (char *buf)
  330. {
  331.     NextCmd = 0;
  332.     free (NextCmdMsg);
  333.     if (Command && Command->screen->statline)        { // Command status line is on
  334.         NextCmdMsg = strdup (buf);
  335.         rip (NextCmdMsg);
  336.         NextCmd = 120;
  337.     }
  338. }
  339.  
  340.  
  341. void displayStatLine (int offset, int phase)
  342. {
  343. struct session *sp, *tochk;
  344. int stop, r;
  345. struct text_info tr;
  346. unsigned char attr, iscmd = 0;
  347. char timebf[9];
  348. short beepit = 0;
  349. static short lastbeep = 0;
  350.  
  351.     if (main_exit)
  352.         return;
  353.     if (!ScreenOwner->screen->statline && offset != 1)
  354.         return;
  355.     if (vgaDesired)
  356.         return;
  357. #ifdef SCREENSAVER
  358.     if (ssenabled ())
  359.         return;
  360. #endif
  361. //    sound (440);
  362.     gettextinfo(&tr);
  363.     if (ScreenOwner == Command)
  364.         iscmd = 1;
  365.     window (1,1,SCREENwidth,(iscmd) ? 2 : 1);
  366.     tochk = Current;
  367.     if ((Current == Trace) || (Current == Command))
  368.         tochk = Lastcurr;
  369.     attr = ((tr.attribute & 0x0f) << 4) + ((tr.attribute & 0x70) >> 4);
  370.     textattr ((offset == 1) ? tr.attribute : attr);
  371.     if (offset)
  372.         clrscr ();
  373.     if (offset != 1)        {
  374.         cprintf (statversion, Nsessions);
  375.         stop = 20;
  376.         if (Nsessions < stop)
  377.             stop = Nsessions;
  378.         for(sp=Sessions; sp < &Sessions[stop];sp++)    {
  379.                 if(sp->type == FREE || sp->type == COMMAND || sp->type == TRACESESSION)    {
  380.                 cprintf ("   ");
  381.                 continue;
  382.                 }
  383.             r = socklen(sp->output,1);
  384.             textattr ( (r) ? attr | 0x80 : attr);
  385.             if (r && !beepit)
  386.                 beepit = 1;
  387.             if (tochk == sp)
  388.                 highvideo ();
  389.             cprintf ("%2d ", sp->index);
  390.             lowvideo ();
  391.             }
  392.         clreol ();
  393.         gotoxy (75, 1);
  394.         _strtime (timebf);
  395.         timebf[5] = 0;        // clip off the seconds
  396.         if (!phase)
  397.             timebf[2] = ' ';
  398.         textattr (attr);
  399.         cprintf (timebf);
  400.         if (iscmd)    {
  401. //            gotoxy (2, 1);
  402. #ifdef CONVERS
  403.             cprintf ("\r\n BBS=%2d CONF=%2d FTP=%2d TUT=%2d  ", BbsUsers, CountConfUsers(), FtpUsers, Tutored);
  404. #else
  405.             cprintf ("\r\n BBS=%2d FTP=%2d TUT=%2d           ", BbsUsers, FtpUsers, Tutored);
  406. #endif
  407.             clreol ();
  408.             if (NextCmd)
  409.                 cprintf ("- %-45.45s", NextCmdMsg);
  410.         }
  411.         if (NextCmd)
  412.             if (!--NextCmd)    {
  413.                 free (NextCmdMsg);
  414.                 NextCmdMsg = 0;
  415.             }
  416.         if (!lastbeep && beepit)
  417.             cprintf ("\007");
  418.         lastbeep = beepit;
  419. //         window (1,2,SCREENwidth,SCREENlength);
  420. //         window (1,2 + iscmd,SCREENwidth,SCREENlength - (ScreenOwner->split * 2) - iscmd - 1);
  421.          window (1,2 + iscmd,SCREENwidth,SCREENlength - (ScreenOwner->split * 2));
  422.         gotoxy (tr.curx, tr.cury + offset + (offset * iscmd));
  423.         }
  424.     else    {
  425. //        window(1,1,SCREENwidth,SCREENlength);
  426.         window(1,1,SCREENwidth,SCREENlength - (ScreenOwner->split * 2));
  427.         gotoxy (tr.curx, tr.cury + 1 + iscmd);
  428.     }
  429.     textattr (tr.attribute);
  430. //    nosound ();
  431. }
  432.  
  433. /* Set status line on/off */
  434. int
  435. dostatline (int argc, char *argv[], void *p)
  436. {
  437. int retval, itwas;
  438.  
  439.     if (vgaDesired)    {
  440.     tprintf ("Status Line not yet functional in EGA/VGA mode, sorry!\n");
  441.     return 0;
  442.     }
  443.     itwas = STATLINE; 
  444.     retval = setbool(&STATLINE,"Status line",argc,argv);
  445.     if (STATLINE && !itwas)    {
  446.      Command->screen->statline = STATLINE;
  447.     displayStatLine (-1, 1);
  448.     }
  449.     if (!STATLINE && itwas)    {
  450.      Command->screen->statline = STATLINE;
  451.     displayStatLine (1, 1);
  452.     }
  453.     return (retval);
  454. }
  455.  
  456. /* Status line toggle */
  457. void
  458. statLineToggle ()
  459. {
  460.     if (vgaDesired)
  461.     return;
  462.     ScreenOwner->screen->statline ^= 1;
  463.     if (ScreenOwner == Command)
  464.     STATLINE = ScreenOwner->screen->statline;
  465.     displayStatLine ((ScreenOwner->screen->statline) ? -1 : 1, 1);
  466. }
  467.  
  468.  
  469. }    // end of extern "C" stuff
  470.  
  471.